<?php

/**
 * 前台控制器
 */
class FrontBaseC extends YzwController {

    public $assetsName = "front";
    public $layout = 'theme.views.layouts.FrontContent';
    public $menus; //主导航
    public $catMenus; //类目列表(栏目数组)
    public $catMenusFix;
    public $actionPath;

    public function init() {
        parent::init();
        //菜单
        $this->catMenus = CategoryModel::model()->getCatMenu();
        $this->catMenusFix = array(
            array(
                'label' => '全部',
                'url' => array('/front/index/index'),
                'itemOptions' => array('class' => 'all'),
            ),
            array(
                'label' => '女装',
                'url' => array('/front/index/index/', 'cid' => '1'),
                'itemOptions' => array('class' => 'womens'),
            ),
            array(
                'label' => '男装',
                'url' => array('/front/index/index/', 'cid' => '2'),
                'itemOptions' => array('class' => 'man'),
            ),
            array(
                'label' => '母婴',
                'url' => array('/front/index/index/', 'cid' => '3'),
                'itemOptions' => array('class' => 'gravida-baby'),
            ),
            array(
                'label' => '鞋类',
                'url' => array('/front/index/index/', 'cid' => '4'),
                'itemOptions' => array('class' => 'shoes'),
            ),
            array(
                'label' => '居家',
                'url' => array('/front/index/index/', 'cid' => '5'),
                'itemOptions' => array('class' => 'furnishing'),
            ),
            array(
                'label' => '美食',
                'url' => array('/front/index/index/', 'cid' => '6'),
                'itemOptions' => array('class' => 'fine-food'),
            ),
            array(
                'label' => '配饰',
                'url' => array('/front/index/index/', 'cid' => '7'),
                'itemOptions' => array('class' => 'bags'),
            ),
            array(
                'label' => '数码',
                'url' => array('/front/index/index/', 'cid' => '9'),
                'itemOptions' => array('class' => 'maquillage'),
            ),
            array(
                'label' => '美妆',
                'url' => array('/front/index/index/', 'cid' => '8'),
                'itemOptions' => array('class' => 'digital'),
            ),
            array(
                'label' => '文体',
                'url' => array('/front/index/index/', 'cid' => '10'),
                'itemOptions' => array('class' => 'sport'),
            ),
        );
    }

    public function runAction($action) {
        //方法名
        defined('ACTION_NAME') or define('ACTION_NAME', $action->getId());
        //访问统计
        try {
            GuestDataModel::model()->record();
        } catch (Exception $exc) {
            
        }
        parent::runAction($action);
    }

    protected function beforeAction($action) {
        //陶牛品的 nofollow:::: 首页不要nofollow 其他的都要
        if (Yii::app()->controller->id == 'index' && $action->id == "index") {
            $linkOptions = array('target' => '_blank');
        } else {
            $linkOptions = array('target' => '_blank', 'rel' => 'nofollow');
        }
        $this->menus = array(
            array('label' => '首页', 'url' => array('/front/index/index')),
            array('label' => '淘牛品', 'url' => 'http://tealife.uz.taobao.com/', 'linkOptions' => $linkOptions,),
            array('label' => '天猫专区', 'url' => array('/front/index/tmall')),
            array('label' => '9.9专区', 'url' => array('/front/cat/jj')),
            //array('label' => '秋冬新款', 'url' => array('/front/index/qing')),
            //array('label' => '美食专场', 'url' => array('/front/index/zhuanchang')),
            array('label' => '下期预告', 'url' => array('/front/cat/tomorrow')),
            //array('label' => '上期热卖', 'url' => array('/front/cat/yesterday', 'cid' => 0)),
            array('label' => '积分兑换', 'url' => array('/front/index/score')),
            //array('label' => '商家报名', 'url' => array('/user/bm/bm')),
            array('label' => MembersSignModel::model()->isSignIn(Yii::app()->user->id) ? '您已签到' : '点击签到', 'url' => 'javascript:void(0);', 'linkOptions' => array('class' => 'qdlabel')),
        );
        $module_id = isset($this->module->id) ? $this->module->id : 'front';
        $this->actionPath = $module_id . $this->getId() . $action->getId();
        parent::beforeAction($action);
        return true;
    }

    /**
     * 过滤数据
     * @param type $arrData 需要过滤的数据
     */
    public function unsetPostData($arrFilterData, $arrData = '') {
        empty($arrData) ? $arrData = $_POST : '';
        foreach ($arrFilterData as $item) {
            if (isset($arrData[$item])) {
                unset($arrData[$item]);
            }
        }
    }

}
